<template>
  <div class="todo-footer">
    <label>
      <input type="checkbox" :checked="doneNum === todos.length ? true:false"
      @change="allChecked($event)"/>
    </label>
    <span>
      <span>已完成{{doneNum}}</span> / 全部{{todos.length}}
    </span>
    <button class="btn btn-danger" @click="clearAllDone">清除已完成任务</button>
  </div>
</template>

<script>
export default{
  props:['todos'],
  data(){
    return {
    }
  },
  created(){

  },
  computed:{
    doneNum(){
      return this.todos.reduce((total,item)=>{
        return total + (item.done ? 1:0)
      },0)
    }
  },
  methods:{
    clearAllDone(){
      this.$emit('clearAllDone')
    },
    allChecked(e){
      this.$emit('allChecked',e.target.checked)
    }
  }
}
</script>

<style>
</style>
